﻿using System;
using System.Text;
using System.Text.RegularExpressions;

namespace Wrox.ProCSharp.Delegates
{
    class Employee
    {
        public Employee(string name, decimal salary, int age)
        {
            Name = name;
            Salary = salary;
            Age = age;

        }
        public string Name { get; }
        public decimal Salary { get; }
        public int Age { get; }


        public override string ToString()
        {
            int sun = 0;//定义一个int类型来存储含义字符串的name字节长度
            //正则表达式//判断name是否含有汉字
                Regex r = new Regex(@"[\u4e00-\u9fa5]+"); 
                Match mc = r.Match(Name);
            if (mc.Length != 0)//不等于0表示含有
            {
                 sun = Encoding.Default.GetByteCount(Name);//    取出name字节长度
            }
            //return String.Format("{0,10}{1,-10}", Name, Salary);      
            //字符长度不够就向右填充👇👇👇
            return "名字：" + Name.PadRight(13 - sun / 3, ' ') + "薪资：" + Salary.ToString().PadRight(15 - Age.ToString().Length) + "年龄：" + Age.ToString();
            //return  Name.PadRight(6,'!')+sun ;
            //+Salary.ToString().PadRight(15 - Age.ToString().Length) + Age.ToString()
            //return $"{Name,-10}{Salary}{Age}";
        }
        public static bool CompareSalary(Employee e1, Employee e2) =>//比较工资
          e1.Salary < e2.Salary;
        public static bool CompareSalaryAge(Employee e1, Employee e2) =>//比较年龄
          e1.Age < e2.Age;
        public static bool CompareSalaryName(Employee e1, Employee e2)//比较名字
        {
            string[] Names = { e1.Name, e2.Name };
            Array.Sort(Names);
            return e1.Name == Names[0];
        }


    }
}
